namespace WGT
{
    public partial class Dialog
    {
        protected bool Button(pos p, string caption, params string[] attrs)
        {
            int id = 0;
            string oldC = null;
            string[] oAttrs = null;
            pos op = null;
            bool rval = false;

            GetPut(ref op, ref p);
            GetPut(ref oAttrs, ref attrs);

            string atf = AttrUtil.First(attrs);
            string ats = AttrUtil.Second(attrs);

            if (mode == MODE.SHOW)
            {
                id = iNextId++;

                S(@"<input id='{0}' type='submit' value='{1}' onclick=a(w.event('{0}')); />", id, caption);
                U(@"p({0},{1},{2},{3},{4});", id, p.y, p.x, p.w, p.h);
                UP(id.ToString(), atf);
                U(@"sc('{0}','{1}');", id, ats);
            }

            GetPut(ref id, ref id);
            string sid = id.ToString();

            if (mode == MODE.UPDATE)
            {
                //if (oldC != caption){
                //    U(@"$('{0}').value={1};", id, caption);
                //}
                if (!p.Equals(op))
                {
                    U(@"p({0},{1},{2},{3},{4});", id, p.y, p.x, p.w, p.h);
                }
                if (attrs != oAttrs)
                {
                    UP(sid, atf);
                    U(@"sc('{0}','{1}');", sid, ats);
                }
            }
            else if (mode == MODE.ERASE)
            {
                E(sid);
            }
            else if (mode == MODE.EVENT)
            {
                if (sender == sid)
                {
                    bUpdate = true;
                    rval = true;
                }
            }

            if (mode != MODE.ERASE)
            {
                if (bHorizontal) gx += p.w;
                else gy += p.h;
            }

            return rval;
        }
    }
}